<template>
<div>
  <el-table
    :data="dataList"
    border
    v-loading="dataListLoading"
    @selection-change="selectionChangeHandle"
    style="width: 100%;"
    size="mini">
    <el-table-column
      type="selection"
      header-align="center"
      align="center"
      width="50">
    </el-table-column>
    <el-table-column
      prop="code"
      header-align="center"
      align="center"
      label="工夹具代码">
    </el-table-column>
    <el-table-column
      prop="seqId"
      header-align="center"
      align="center"
      label="工夹具序列号">
    </el-table-column>
    <el-table-column
      prop="submitName"
      header-align="center"
      align="center"
      label="申请人">
    </el-table-column>
    <el-table-column
      prop="repairReason"
      header-align="center"
      align="center"
      label="故障原因">
    </el-table-column>
    <el-table-column
      prop="submitTime"
      header-align="center"
      align="center"
      label="申请时间">
    </el-table-column>
    <el-table-column
      prop="status"
      header-align="center"
      align="center"
      label="处理状态">
      <template slot-scope="scope">
        <span v-if="scope.row.status === '0'">已同意</span>
        <span v-else>未同意</span>
      </template>
    </el-table-column>
    <el-table-column
      fixed="right"
      header-align="center"
      align="center"
      width="150"
      label="操作">
      <template slot-scope="scope">
        <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)" style="color: #409EFF">查看</el-button>
        <el-button type="text" size="small" >通过</el-button>
        <el-button type="text" size="small" style="color:#F8836C;" @click="open">不通过</el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    @size-change="sizeChangeHandle"
    @current-change="currentChangeHandle"
    :current-page="dataForm.pageIndex"
    :page-sizes="[10, 20, 50, 100]"
    :page-size="dataForm.pageSize"
    :total="totalPage"
    layout="total, sizes, prev, pager, next, jumper">
  </el-pagination>
  <detail v-if="addOrUpdateVisible" ref="detail" @refreshDataList="getDataList"></detail>
</div>
</template>

<script>
import Detail from "../repair/repairsubmitminereviewdetail";

export default {
  name: "repairsubmitminereview",
  data () {
    return {
      value1:'',
      labelPosition:'left',
      options: [{
        value: 0,
        label: '初审未通过'
      }, {
        value: 1,
        label: '初审通过'
      }, {
        value: 2,
        label: '终审未通过'
      }, {
        value: 3,
        label: '终审通过'
      }],
      dataForm: {
        pageIndex: 1,
        pageSize: 10,
      },
      dataList: [],
      // pageIndex: 1,
      // pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    Detail
  },
  computed:{
    // startPickerOptions(){
    //   //选择的日期
    //   let curDate = this.$moment(this.startDate).format("YYYY-MM-DD");
    //   //最小日期
    //   let minDate = this.$moment(this.minTime).format("YYYY-MM-DD");
    //   //前推一天，防止当天日期无法选择
    //   let preTime = this.minTime-24*3600000;
    //   // 如果选择的日期为最小日期，则设置为最小日期的时分秒
    //   let str = "";
    //   if(curDate == minDate){
    //     str = this.$moment(this.minTime).format("HH:mm:ss");
    //   }else{
    //     str = "00:00:00"
    //   }
    //   return {
    //     disabledDate: (time) => {
    //       return time.getTime() < preTime || time.getTime() > this.maxTime;
    //     },
    //     selectableRange: str + " - 23:59:59"
    //   }
    // },
  },
  activated () {
    this.getDataList()
  },
  methods: {
    open() {
      this.$prompt('请输入不通过的理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '你的理由是: ' + value
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
    getDataListByLike(){
      this.$http.post(`http://localhost:10000/gongjiajumain/scrapsubmithistory/getformdata`,this.dataForm)
        .then(res=>{
          console.log(this.dataForm)
          console.log("传输成功")
        })
    },
    //清空表格
    clearDataForm(){
      this.dataForm = {}
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http.post(`http://localhost:10000/gongjiajumain/repairsubmit/list1`,this.dataForm)
        .then(data=>{
          if (data.data && data.data.code === 0) {
            this.dataList = data.data.page.list
            this.totalPage = data.data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.dataForm.pageSize = val
      this.dataForm.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.dataForm.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.detail.init(id)
      })
    },
    // 删除
    deleteHandle (id) {
      var ids = id ? [id] : this.dataListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: "http://localhost:10000/gongjiajumain/scrapsubmithistory/delete",
          method: 'post',
          data: this.$http.adornData(ids, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
